import { isEmpty as isEmptyLodash } from 'lodash-es'
import { showToast, closeToast } from 'vant'

export default {
  //值是否为空
  isEmpty(valua) {
    return isEmptyLodash(valua)
  },

  // 全局toast
  toast(text = '', duration = 2000) {
    return showToast({
      message: text,
      duration: duration,
    })
  },

  // 隐藏Toast
  hideToast() {
    closeToast()
  },

  // 校验投注金额
  verifyBetAmount(list) {
    let isLegalAmount = false
    if (this.isEmpty(list)) {
      this.toast(`请下注`)
      return isLegalAmount
    }
    for (const item of list) {
      if (item.betAmount < item.singleMinLimit) {
        this.toast(`每注金额不能低于${item.singleMinLimit}`)
        break
      }
      if (item.betAmount > item.singleMaxLimit) {
        this.toast(`每注金额不能大于${item.singleMinLimit}`)
        break
      }
      isLegalAmount = true
    }
    return isLegalAmount
  },
}
